package com.forum.controller.photo;

import com.common.entity.ApiResult;
import com.common.utils.LocalContext;
import com.forum.impl.photo.PhotoCategoryServiceImpl;
import com.forum.impl.photo.PhotoWallServiceImpl;
import com.forum.pojo.photo.PhotoWall;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Tsing
 */
@RestController
@RequestMapping("photowalls")
//@CrossOrigin(origins = "*")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PhotoWallController {

    public final PhotoCategoryServiceImpl photoCategoryService;
    public final PhotoWallServiceImpl photoWallService;

    // 1、Get Photo Category ; 获取照片墙-照片分类
    @GetMapping("/getPhotoCategory")
    public ApiResult<?> GetHomeCarouselList(){
        return ApiResult.success(photoCategoryService.list());
    }

    // 2、Get Photo By Category and Current and Size
    @GetMapping("/getPhoto")
    public ApiResult<?> getPhoto(@RequestParam("page") Integer page,
                                 @RequestParam("size") Integer size,
                                 @RequestParam("categoryId") Integer categoryId){
        return photoWallService.getPhoto(page, size, categoryId);
    }

    // 3、Post a set of images 发布一组图片
    @PostMapping("/submitImages")
    public ApiResult<?> submitImages(@RequestBody PhotoWall photoWall){
        photoWall.setPublisherId(LocalContext.getCurrentUserId());
        return photoWallService.submitImages(photoWall);
    }

    // 4、get Recommend Photo 获取推荐的照片
    @GetMapping("/getRecommendPhoto")
    public ApiResult<?>getRecommendPhoto(@RequestParam("page") Integer page,
                                         @RequestParam("size") Integer size){
        return photoWallService.getRecommendPhoto(page,size);
    }
    // 5、get PhotoWall Detail
    @GetMapping("/getPhotoDetail")
    public ApiResult<?>getRecommendPhoto(@RequestParam("photoWallId") Integer photoWallId){
        return photoWallService.getPhotoDetail(photoWallId);
    }

    // 6、like photos 对照片墙进行点赞
    @PutMapping("/likePhoto")
    public ApiResult<?> likePhoto(@RequestParam("likeState") boolean likeState,
                                  @RequestParam("photoWallId") Integer photoWallId){

        return  photoWallService.likePhoto(likeState,photoWallId);
    }

    // 7、Get My Photo Walls
    @GetMapping("/getMyPhotoWalls")
    public ApiResult<?> getMyPhotoWalls(@RequestParam("page") Integer page,
                                        @RequestParam("size") Integer size){
        return  photoWallService.getMyPhotoWalls(page,size);
    }
}
